package com.zhu.tool_test.datastructure.queue;

import java.util.List;
import java.util.Queue;
import java.util.concurrent.*;

/**
 * @program: tool_test
 * @description: 利用队列实现消息队列
 * @author: ggBall
 * @create: 2021-03-03 16:01
 **/
public class MqDemo {

    /**
     * 消息队列
     */
    private static Queue<String> queue;


    /**
     * 存放消费者的池
     */
    private ExecutorService executorService = Executors.newFixedThreadPool(10);


    public static void main(String[] args) {
        // 准备 容量为10的消息队列
        queue = new ArrayBlockingQueue<String>(10);
        // 准备消费者
        Consumer consumer = new Consumer(queue);
        // 准备生产者
        Producer producer = new Producer(queue);


        // 产生消息
        for (int i = 0; i < 10; i++) {
            producer.send(i+"");
        }

        // 消费消息
        List<String> consume = consumer.consume(10);
        System.out.println("consume = " + consume);
    }
}
